#include "I_BaseLib.h"


WSTRING::WSTRING(const wchar_t *temp)
{
 	size_t l = wcslen(temp)+1;
	data = (wchar_t *) new wchar_t[l];
	memcpy(data,temp,l*sizeof(wchar_t));
	
}

WSTRING::WSTRING(const char *temp)
{
	size_t l = strlen(temp)+1;
	data = (wchar_t *) new wchar_t[l];
	for (size_t i=0;i<l;i++)
		data[i]=temp[i];

}

void WSTRING::operator=(const wchar_t * temp)
{

	if (data!=0) delete data;
	size_t l = wcslen(temp)+1;
	data = (wchar_t *) new wchar_t[l];
	memcpy(data,temp,l*sizeof(wchar_t));
	
}

size_t WSTRING::Length()
{

	return 	wcslen(data);

}

void WSTRING::Concat(WSTRING &temp)
{
	
	WSTRING temp2 = this->data; //backup current string data
	size_t currentlength = this->Length(); //how long is the current string
	if (data!=0) delete data; //delete current one
	data = new wchar_t[currentlength + temp.Length() + 1]; //realloc memory
	memcpy(data,temp2.data,currentlength * sizeof(wchar_t)); //copy first string from backup
	memcpy(data+currentlength,temp.data,(temp.Length() + 1)* sizeof(wchar_t)); //copy second part from parameter
	
}